<?php

namespace app\api\controller\order;

use app\api\controller\Controllers;
use app\api\service\order\Order as OrderService;
use app\api\service\common\Pay;
use app\api\model\order\Order as OrderModel;

class Order extends Controllers
{

    /**
     * 下单操作
     *
     * @return \think\Response
     */
    public function set( OrderService $service )
    {
        $post = $this->request->only(['id', 'cid', 'total'], 'post');
        $order = $service->set($post);
        return success();
        $pay = new Pay([
            'order_number'=>$order->order_number,
            'total' => $order->price,
            'start_time' => date("YmdHis", strtotime($order->create_at)),
            'expire_time' => date("YmdHis", strtotime($order->create_at)+60*30),
            'body' => $order->curriculum_title
            ]);
        return success($pay->xcx());
    }

    /**
     * 获取订单列表
     *
     * @return \think\Response
     */
    public function lists( OrderService $service )
    {
        return success($service->lists());
    }

    /**
     * 获取订单详情
     *
     * @return \think\Response
     */
    public function read( OrderService $service, int $id )
    {
        return success($service->read($id));
    }

    /**
     * 取消订单
     * @param int $id
     * @param OrderService $service
     * @return \think\Response
     */
    public function cancel( int $id, OrderService $service )
    {
        return $service->cancel($id)?success():failed('服务错误');
    }

}
